/**
 * Description:
 * Class Name:CalendarTest
 * Date:2022/2/21 15:35
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第7章_Java基础类库._7_4_Java8的日期_时间类._7_4_2_Calendar类;

import java.util.Calendar;

public class CalendarTest {
    public static void main(String[] args) {
        var c = Calendar.getInstance();
        // 取出年、月、日
        System.out.println(c.get(Calendar.YEAR));
        System.out.println(c.get(Calendar.MONTH));
        System.out.println(c.get(Calendar.DATE));
        // 分别设置年月日，小时、分钟、秒
        c.set(2003,10,23,12,32,23);     // 2003-11-23 12:32:23
        System.out.println(c.getTime());
        // 将Calendar往前推一年
        c.add(Calendar.YEAR, -1);       // 2002-11-23 12:32:23
        System.out.println(c.getTime());
        // 将Calendar往前推一个月
        c.roll(Calendar.MONTH, -8);     // 2002-3-23 12:32:23
        System.out.println(c.getTime());
    }
}
